package com.supermap.dataservice.vip.cq;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;
import java.util.Map;

/**
 * @author aqua
 * @description
 * @date 2018年11月12 上午 11:02
 * @email 1301584033@qq.com
 */
@Mapper
public interface CqVipProductMapper {

    /**
     * 统计专业服务产品数量getExpert
     * */
    @SelectProvider(type =CqVipProductMapperSQL.class,method = "getVipProductCountNumSQL")
    List<Map<String,Object>> getVipProductCountNum(@Param("beginTime")String beginTime, @Param("endTime")String endTime, @Param("pageNum")String pageNum, @Param("pageSize")String pageSize);

    /**
     *
     *  专家建议
     * */
    @SelectProvider(type = CqVipProductMapperSQL.class,method = "getCqProfvipcontentSQL")
    List<Map<String,Object>> getCqProfvipcontent(@Param("farmId")String farmId,@Param("pageNum")String pageNum,@Param("pageSize")String pageSize);

    class CqVipProductMapperSQL{
        public String getCqProfvipcontentSQL(Map<String,Object> map){
            String farmId=(String)map.get("farmId");
            String pageNum=(String)map.get("pageNum");
            String pageSize=(String) map.get("pageSize");
            StringBuilder stringBuilder =new StringBuilder();
            stringBuilder.append("select t.nper,t.content, date_format(createtime,'%Y-%m-%d %H:%i:%S') as createtime from t_profvipcontent t ");
            if(farmId!=null){
                stringBuilder.append("  where t.farm="+farmId+" ");
            }
            stringBuilder.append("order by t.createtime desc ");
            if(pageNum!=null && pageSize!=null){
                stringBuilder.append(" LIMIT "+ (Integer.valueOf(pageNum)-1)*Integer.valueOf(pageSize)+","+pageSize+"");
            }
            return  stringBuilder.toString();

        }


        public String getVipProductCountNumSQL(Map<String,Object> map){
            String beginTime=(String) map.get("beginTime");
            String endTime=(String) map.get("endTime");
            String pageNum=(String)map.get("pageNum");
            String pageSize=(String) map.get("pageSize");
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("select  t1.departname,count(t2.id) as num from t_s_depart t1\n" +
                    "left join t_profvipcontent t2\n" +
                    " on t1.depareacode=t2.areacode ");
            if(beginTime!=null && endTime !=null){
                stringBuilder.append(" and t2.createtime between '"+beginTime+"' and  '"+endTime+"' ");
            }
            stringBuilder.append(" group by t1.id ");
            if(pageSize!=null && pageNum!=null){
                stringBuilder.append("limit  "+pageNum+","+pageSize+" ");
            }
            return  stringBuilder.toString();
        }
    }
}
